package com.im.message.controller;

import com.im.common.utils.Result;
import com.im.message.entity.Group;
import com.im.message.entity.Message;
import com.im.message.entity.User;
import com.im.message.service.GroupService;
import com.im.message.service.MessageService;
import com.im.message.service.UserService;
import com.im.message.vo.MessageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * User: key
 * ClassName:MessageController
 * Date: 2023/7/10
 * Time: 16:29
 * description:
 */
@RestController
public class MessageController {

    @Autowired
    private MessageService messageService;

    @Autowired
    private UserService userService;

    @Autowired
    private GroupService groupService;



    /**
     * 查询消息列表的接口
     * */
    @GetMapping("/list")
    public List<MessageVo> getByIdNums(){
        List<Message> list1 = messageService.list();
        List<MessageVo> list = new ArrayList<>();
        List<User> list2 = userService.list();
        List<Group> list3 = groupService.list();
        for (int i = 0; i < list1.size(); i++) {
            Message message = list1.get(i);
            Group group = list3.get(i);
            User user = list2.get(i);
            MessageVo messageVo = new MessageVo();
            messageVo.setUnreadCount(message.getUnreadCount());
            messageVo.setType(message.getType());
            messageVo.setContext(message.getContext());
            messageVo.setCreateTime(message.getCreateTime());
            messageVo.setGroup(group);
            messageVo.setUser(user);
            list.add(messageVo);
        }
        return list;
    }
}
